<?php
/**
 * Radcodes - SocialEngine Module
 *
 * @category   Application_Extensions
 * @package    Story
 * @copyright  Copyright (c) 2009-2010 Radcodes LLC (http://www.radcodes.com)
 * @license    http://www.radcodes.com/license/
 * @version    $Id$
 * @author     Vincent Van <vincent@radcodes.com>
 */
?>
<?php 
  $this->headLink()
    ->appendStylesheet('application/modules/Story/externals/styles/annotation.css'); 
	$this->headLink()
    ->appendStylesheet('application/modules/Story/externals/css/jquery.selectbox.css'); 
?>

<?php $this->headScript()->appendFile('application/modules/Story/externals/scripts/jquery-1.7.1.js') ?>
<?php $this->headScript()->appendScript('jQuery.noConflict();') ?>
<?php $this->headScript()->appendFile('application/modules/Story/externals/scripts/jquery-ui-1.8.17.js') ?>
<?php $this->headScript()->appendFile('application/modules/Story/externals/scripts/jquery.annotate.js') ?>
<script language="javascript" src="application/modules/Story/externals/js/jquery.selectbox-0.2.js"></script>
<script language="javascript">
	jQuery.noConflict();
	<?php if($this->photo_url): ?>
	jQuery(window).load(function() {		
		jQuery("#toAnnotate").annotateImage({
			getUrl: "<?php echo $this->baseUrl();?>/stories/comics/<?php echo $this->photo_id; ?>/get-bubbles",
			saveUrl: "<?php echo $this->baseUrl();?>/stories/comics/<?php echo $this->photo_id; ?>/save-bubble",
			deleteUrl: "<?php echo $this->baseUrl();?>/stories/comics/<?php echo $this->photo_id; ?>/delete-bubble",
			editable: false
		});
	});	
	<?php endif; ?>
</script>


<style type="text/css">
.chapter_container {
	text-align: left;
	width: 200px;
}

.chapter_container a.active {
	font-weight: bold;
}
.photo_description {
	float: right;
	font-weight: bold;
	font-style: italic;	
}
.generic_layout_container .layout_story_profile_body {
	margin-bottom: 15px;
}
.layout_middle, #global_page_story-profile-index{
	overflow: visible;
}
</style>

<?php 
$story = $this->story;
$chapters = $story->getChapters();
?>

<?php if(count($chapters->toArray())>0){ ?>
<div class='story_profile_info' style="margin-bottom: 5px;">
  <ul>   
<?php if($this->chapter == null): ?>
    <li><?php echo $this->translate('Posted by %s', $this->last_chapter->getOwner()->toString()); ?></li>
<?php else: ?>
	<li><?php echo $this->translate('Posted by %s', $this->chapter->getOwner()->toString()); ?></li>
<?php endif; ?>
  </ul>
</div>
<?php } ?>

<?php if(count($chapters->toArray())>0){ ?>
<select class="chapter_container" onchange="document.location.href=this.value">
<?php 
$index = 1;
foreach($chapters as $chapter):
$active = "";
if($this->chapter_id == $chapter->chapter_id){
	$active = "selected='selected'";
}
?>
<option value="<?php echo $chapter->getHref(); ?>" <?php echo $active ?>>Chapter <?php echo $index;?></option>
<?php 
$index++;
endforeach; 
?>
</select>
<?php } ?>
<script language="javascript">
	j(".chapter_container").selectbox({
		onChange: function (val, inst) {
			document.location.href=val;
		},
		effect: "slide"
	});
</script>

<?php if($this->chapter == null): ?>
<div class='story_profile_body'>
  <?php if(!empty($this->last_chapter)) echo $this->last_chapter->body;
  else echo $story->body; ?>
</div>
<?php if($this->story->category_id == Story_Model_Category::COMICS):?>
<div id="image_comic" style="display: block; text-align: center">
	<img id="toAnnotate" src="<?php echo $this->photo_url; ?>"/>
	<?php if($this->photo): ?>
	<div class="photo_description">
		<?php echo $this->photo->getTitle(); ?>
	</div>
	<?php endif; ?>
</div>
<?php endif; ?>
<?php else: ?>
<div class='story_profile_body'>
  <?php echo $this->chapter->body; ?>
</div>
<?php endif; ?>
